package samsung.yx;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Poj2676_03 {

	static int flag;
	static int[][] yuan = new int[81][3];
	static int[][] data = new int[10][10];

	public static void main(String[] args) throws FileNotFoundException {
		Scanner sc = new Scanner(new FileInputStream(
				"C:\\Users\\tstcit\\Desktop\\samsung_yx\\Poj2676.txt"));

		//Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while (T-- > 0) {
			for (int i = 1; i <= 9; i++) {
				String str = sc.next();
				for (int j = 1; j <= 9; j++) {
					//char[] c = str.toCharArray();
					String a = str.substring(j - 1, j);
					data[i][j] = (a.equals("1") ? 1 : (a.equals("2") ? 2 : (a
							.equals("3") ? 3 : (a.equals("4") ? 4 : (a
							.equals("5") ? 5 : (a.equals("6") ? 6 : (a
							.equals("7") ? 7 : (a.equals("8") ? 8 : (a
							.equals("9") ? 9 : 0)))))))));
					// System.out.print(data[i][j]);
				}
				// System.out.println();
			}
			flag = 0;
			DFS(1);
		}
	}

	public static void DFS(int m) {
		int i, j;
		i = (m - 1) / 9 + 1;
		j = m - (i - 1) * 9;
		if (m > 81) {
			flag = 1;
			printA();
			return;
		}
		if (data[i][j] != 0) {
			DFS(m + 1);
		} else {
			for (int k = 1; k <= 9; k++) {
				if (isSafe(m, k) == 1) {
					data[i][j] = k;
					DFS(m + 1);
					data[i][j] = 0;
					if (flag == 1) {
						return;
					}
				}
			}
		}
		return;
	}

	public static int isSafe(int key, int value) {
		int i = (key - 1) / 9 + 1;
		int j = key - (i - 1) * 9;
		for (int k = 1; k <= 9; k++) {
			if (value == data[i][k]) {
				return 0;
			}
		}
		for (int k = 1; k <= 9; k++) {
			if (value == data[k][j]) {
				return 0;
			}
		}
		if (i <= 3) {
			i = 1;
		}
		if (i > 3 && i < 7) {
			i = 4;
		}
		if (i >= 7) {
			i = 7;
		}
		if (j <= 3) {
			j = 1;
		}
		if (j > 3 && j < 7) {
			j = 4;
		}
		if (j >= 7) {
			j = 7;
		}
		for (int x = 0; x < 3; x++) {
			for (int y = 0; y < 3; y++) {
				if (data[x + i][y + j] == value) {
					return 0;
				}
			}
		}
		return 1;
	}

	public static void printA() {
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				System.out.print(data[i][j]);
			}
			System.out.println();
		}
	}
}
